package com.longrise.co.ui.carlife.fragment;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.longrise.co.R;
import com.ly.common.base.BaseFragment;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/17.
 */

public class InspectRuleFragment extends BaseFragment {


    @Bind(R.id.head_title)
    TextView headTitle;
    @Bind(R.id.inspectrule_tv)
    TextView inspectruleTv;

    private String getStringFromAsset(String filename) {
        BufferedReader br = null;
        try {
            StringBuilder sb = new StringBuilder();
            InputStream is = getContext().getAssets().open(filename);
            String line;
            br = new BufferedReader(new InputStreamReader(is));
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\r\n");
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                }
            }
        }
        return null;
    }

    public static InspectRuleFragment newInstance() {
        
        Bundle args = new Bundle();
        
        InspectRuleFragment fragment = new InspectRuleFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fg_view_inspectrule;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    protected void initView() {
        //标题栏
        setText(headTitle, "《车辆年检和处罚规则》");
        inspectruleTv.setMovementMethod(new ScrollingMovementMethod());
        inspectruleTv.setText(getStringFromAsset("inspectrule.txt"));
    }



    @OnClick(R.id.head_back)
    public void onViewClicked() {
        _mActivity.onBackPressed();
    }
}
